package com.platform.apex.cma.tools;


import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;

/**
 * 对象与JSON转换通操作类
 *
 */
public class ObjectMapperUtil {

	private final static String locker = "locker";
	/**
	 * 
	 */
	private static ObjectMapper OBJECT_MAPPER_FOR_ROUTING;

	/**
	 * 获取ObjectMapper操作类对象
	 * @return ObjectMapper 对象
	 */
	public static ObjectMapper abtainObjectMapper() {
		
		if (OBJECT_MAPPER_FOR_ROUTING == null){
			synchronized (locker) {
				if (OBJECT_MAPPER_FOR_ROUTING == null){
					OBJECT_MAPPER_FOR_ROUTING = new ObjectMapper();
				}
			}
			OBJECT_MAPPER_FOR_ROUTING.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
			OBJECT_MAPPER_FOR_ROUTING.configure(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT, true);
			OBJECT_MAPPER_FOR_ROUTING.configure(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL, true);
			OBJECT_MAPPER_FOR_ROUTING.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
		}
		return OBJECT_MAPPER_FOR_ROUTING;
	}
	
}
